unit SelectBook;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids, Db;

type
  TfmSelectBook = class(TForm)
    DBGrid1: TDBGrid;
    DataSrc: TDataSource;
    procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBGrid1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function Execute(DS: TDataSet): integer;
  end;

var
  fmSelectBook: TfmSelectBook;

implementation

{$R *.DFM}

{ TfmSelectBook }

function TfmSelectBook.Execute(DS: TDataSet): integer;
begin
  DataSrc.DataSet := DS;
  result := -1;
  if ShowModal = mrOk then
    result := DataSrc.DataSet.FieldByName('ID').AsInteger;
end;

procedure TfmSelectBook.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case Key of
    13: ModalResult := mrOk;
    27: ModalResult := mrCancel;
  end;  
end;

procedure TfmSelectBook.DBGrid1DblClick(Sender: TObject);
begin
  ModalResult := mrOk; 
end;

end.
